package com.crm.jdy.controller.client;
import com.crm.jdy.common.utils.UpLoadUtil;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;

@Validated
@Api(tags = "upload", description ="文件上传接口")
@RestController
@RequestMapping("/upload")
public class FileUploadController {

    @RateLimit()
    @ApiOperation("文件上传接口")
    @PostMapping("/fies")
    @ResponseBody
    public ResultVo upload(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return ResultVo.failed("上传失败，请选择文件");
        }
        try {
            String upload = UpLoadUtil.upload(file, "");
            System.out.println("-----文件上传---------");
            System.out.println(upload);
            return ResultVo.success("http://192.168.0.123:5656"+upload);
        } catch (IOException e){
            e.printStackTrace();
        }
        return ResultVo.failed("上传失败！");
    }

}
